package com.ruix.app.widget;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.ruix.app.R;
import com.ruix.app.model.Comment;
import com.ruix.app.model.PostsCard;
import com.ruix.app.util.CopyUtil;
import com.ruix.app.util.ToastUtil;

/**
 * Created by hadexs on 2017/4/30.
 */

public class SharePostDialog extends Dialog implements View.OnClickListener{


    private PostsCard postsCard;
    private Comment comment;
    private int position;
    private DeleteCommentListener listener;

    public SharePostDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_share_post);
        setCanceledOnTouchOutside(true);
        //初始化界面控件
        //初始化界面控件的事件
        initEvent();
        Window dialogWindow = getWindow();
        WindowManager wm = (WindowManager) getContext()
                .getSystemService(Context.WINDOW_SERVICE);
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        lp.width = wm.getDefaultDisplay().getWidth();
        lp.height =(int)getContext().getResources().getDimension(R.dimen.h_w_110);
        dialogWindow.setGravity(Gravity.BOTTOM);

    }

    private void initEvent(){
//        findViewById(R.id.tv_copy_comment).setOnClickListener(this);
//        findViewById(R.id.tv_delete_comment).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.tv_copy_comment:
                dismiss();
                CopyUtil.clipboardCopy(getContext(),comment.getContent());
                ToastUtil.showNewSuccessMsg("已复制");
                break;
            case R.id.tv_delete_comment:
                dismiss();
                if (listener != null){
                    listener.deleteCommentPositive(postsCard,position);
                }
                break;
        }
    }

    public void setListener(DeleteCommentListener listener) {
        this.listener = listener;
    }



    public void show(PostsCard item, int commentPosition){
        if (item != null) {
            this.postsCard = item;
            this.position = commentPosition;
            this.comment = item.getComments().get(commentPosition);
            show();
        }
    }

    public interface DeleteCommentListener{
        void deleteCommentPositive(PostsCard item, int commentPosition) ;
    }
}
